#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :用户画像.py
# @Time      :2024/11/27 
# @Author    :CL
# @email     :1037654919@qq.com

from scrapy_juliangsuanshu import *
def get_portrait_run(keyword,app_name,datestart,dateend):

    while datestart <= dateend:
        date = datestart.strftime('%Y%m%d')
        print('当前进度：', date, end=' ')
        dateend += datetime.timedelta(days=6)
        enddate =dateend.strftime('%Y%m%d')
        datestart += datetime.timedelta(days=1)
        dataxx = pd.DataFrame()
        try:
            datastr = get_portrait(keyword=keyword, start_date=date, end_date=enddate, app_name=app_name)
            datas = decrtptlx(datastr)

            datas = eval(datas)
            data = datas['data']
            for number in data:
                for label_list in number['label_list']:
                    dataxx = dataxx.append(
                        [{'keyword': keyword,
                          'start_date': date,
                          'end_date': enddate,
                          'name_en': number['name_en'],
                          'name_zh': number['name_zh'],
                          'label_id': label_list['label_id'],
                          'name_cate': label_list['name_zh'],
                          'value': label_list['value'],
                          'tgi': label_list['tgi'],
                          'app_name': app_name}],
                        ignore_index=True)

        except:pass
if __name__ == '__main__':
    get_portrait(keyword='游戏', app_name='app', datestart=datetime.datetime(2024, 1, 1), dateend=datetime.datetime(2024, 1, 31))
